package com.zxy.supplier_system.server.controller

import com.zxy.supplier_system.server.entity.Authority
import com.zxy.supplier_system.server.service.ProcurementService
import com.zxy.supplier_system.server.utils.IntIdAndName
import org.springframework.data.domain.Pageable
import org.springframework.data.domain.Slice
import org.springframework.web.bind.annotation.*
import java.math.BigDecimal
import java.time.OffsetDateTime

@RestController
@RequestMapping("procurementSuppliers/{supplierId}/orders")
class ProcurementsOrderController(
    private val procurementService: ProcurementService
) {

    data class AddProcurementRequest(
        val createdDateTime: OffsetDateTime?,
    )

    @HasAnyAuthority(Authority.采购_下单)
    @PostMapping
    fun createProcurement(@PathVariable supplierId: Int,@RequestBody request: AddProcurementRequest):Int{
        return this.procurementService.createProcurement(supplierId,request)
    }

    @HasAnyAuthority(Authority.采购_查询)
    @GetMapping
    fun queryProcurementInMarket(@PathVariable supplierId: Int, pageable: Pageable):Slice<QueryProcurementInSupplierResponse>{
        return this.procurementService.queryProcurementInSupplier(supplierId,pageable)
    }

    data class QueryProcurementInSupplierResponse(
        val id:Int,
        val createdBy: IntIdAndName,
        val createdDateTime: OffsetDateTime,
        val goodsKindAmount:Int,
        val submittedDateTime: OffsetDateTime?,
        val totalFee:BigDecimal,
    )



}